import os
import sys


def xgen(lst, dt, decmin, decmax):
    LST = lst
    dt = dt
    dec0 = decmin
    dec1 = decmax
    t1 = LST - dt       # west
    t2 = LST + dt + 3   # east

    i = 0
    obslist = "obslist.txt"
    if os.access(obslist, os.F_OK):
        os.remove(obslist)

    for t in range(t1, t2, 1):
        print(t)
        if t >= 24:
            ra = (t - 24) * 15
        elif t < 0:
            ra = ( t + 24 ) * 15
        else:
            ra = t * 15
        for dec in range(dec0, dec1, 5):
            print(dec)
            i = i + 1
            sname = "sb" + str(i)
            print(f'sname={sname}')
            radec = "%s %.5f %.5f\n" % (sname, ra, dec)
            xff = open(obslist, 'a+')
            xff.write("%s %.5f %.5f\n" % (sname, ra, dec))
            xff.close()

    print(f'The output observation list is {obslist}')

if __name__ == "__main__":
    #LST = sys.argv[1]  #for local Sidereal time
    LST = 23   # an example
    dt = 1   # delta time in degree
    dec0 = -10  #min for dec
    dec1 = 85   #max for dec.
    xgen(LST, dt, dec0, dec1)